//her startes fullPage.js der giver vores one page effekt, med touchscroll slået fra
$(document).ready(function() {
	$.fn.fullpage({
		anchors: ['firstPage', 'secondPage', '3rdPage', 'lastPage'],
		scrollingSpeed: 500,
		touchSensitivity: 500,
		verticalCentered: true,
	});
});

//starten af Gmaps
var timer;
var map;
var lat1 = -12.043333;
var lng1 = -77.028333;
$(document).ready(
timer = setInterval(
function(){

//opretter et map
  var map = new GMaps({
	el: '#map',
	lat: lat1,
	lng: lng1,
	panControl: false,
	zoomControl: false,
	mapTypeControl: false,
	scaleControl: false,
	streetViewControl: false,
	overviewMapControl: false
  });
  
  //finder din position, og tegner en cirkel på destinations stedet
  GMaps.geolocate({
	success: function(position){
		lat1 = position.coords.latitude;
		lng1 = position.coords.longitude;
	  map.setCenter(lat1, lng1);
	  map.drawCircle({
	lat: 56.120628,
	lng: 10.159618,
	radius: 50,
	strokeColor: '#432070',
	strokeOpacity: 1,
	strokeWeight: 3,
	fillColor: '#432070',
	fillOpacity: 0.6
  });
  //tegner en rute fra dig til destinations stedet.
  map.drawRoute({
		origin: [lat1, lng1],
		destination: [56.120628, 10.159618],
		travelMode: 'walking',
		strokeColor: '#131540',
		strokeOpacity: 0.6,
		strokeWeight: 6
	});
	//optæller afstanden fra dig til destinations stedet. og opretter link og aktivere addEventListener('shake') nå du er inden for 50 meter, og stopper Gmaps opdatering.
	map.getRoutes({
		origin: [lat1, lng1],
		destination: [56.120628, 10.159618],
		callback: function (e) {
			var time = 0;
			var distance = 0;
			for (var i=0; i<e[0].legs.length; i++) {
				time += e[0].legs[i].duration.value;
				distance += e[0].legs[i].distance.value;
			}
			$('#Distance').text(distance+' Meters');
			if(distance < 50){
					$("#close").text("");
						$('<a>',{
							text:'Click here to collect your Shakepoints',
							href:'http://tehwarrer.dk/src/mobile.php#3rdPage'
						}).appendTo('#close');
						clearInterval(timer);
						window.addEventListener('shake', shakeEventDidOccur, false);
			}}
	});},
	error: function(error){
	  alert('Geolocation failed: '+error.message);
	},
	not_supported: function(){
	  alert("Your browser does not support geolocation");
	},
	always: function(){	
	}
  });},5000));

//opdager ryst og sender dig til mobile_collect.php
function shakeEventDidOccur () {
	window.location = "mobile_collect.php";
}